﻿using LightingPlatform.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LightingPlatform.View.Level5
{
    public class ProductSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.ProductTypes); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Class = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Class)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class AreaSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.UseArea); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Place = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Place)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class OrginSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.Orgin); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Orgin = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Orgin)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ImpactSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.ImpactType); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Physical.Impact = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Physical.Impact)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ExplainSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.LightingExplain); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Optics.Explain = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Optics.Explain)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class VoltageSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.WorkVoltage); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Electric.Voltage = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Electric.Voltage)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class ControlTypeSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.ControlType); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Electric.ControlType = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Electric.ControlType)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class AdapterClassSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.LightingType); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.AdapterLighting.Class = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.AdapterLighting.Class)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }

    public class SetupSourceProvider : ISourceProvider
    {
        public IEnumerable<ResItem> ItemSource
        {
            get { return LightingContext.Singleton.GetResourceItems(ResourceType.SetupType); }
        }

        public void SetValue(LightingViewModel vm, uint value)
        {
            vm.Project.Setup = value;
        }

        public int GetValue(LightingViewModel vm)
        {
            int index = 0;
            foreach (ResItem resItem in ItemSource)
            {
                if (resItem.ItemID == vm.Project.Setup)
                {
                    return index;
                }

                index++;
            }
            return 0;
        }
    }
}
